﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script type="text/javascript" src="../../../Content/highlighter/scripts/shCore.js"></script>
    <script type="text/javascript" src="../../../Content/highlighter/scripts/shBrushJScript.js"></script>
    <script type="text/javascript" src="../../../Content/highlighter/scripts/shBrushCSharp.js"></script>
    <script type="text/javascript" src="../../../Content/highlighter/scripts/shBrushXml.js"></script>
    <link type="text/css" rel="stylesheet" href="../../../Content/highlighter/styles/shCore.css" />
    <link type="text/css" rel="stylesheet" href="../../../Content/highlighter/styles/shCoreEclipse.css" />
    <script type="text/javascript">SyntaxHighlighter.all();</script>
</head>
<body>
    <h3>添加操作</h3>
    <p>
        默认情况下，项目的Index控制器都带有Index操作,<br />
        return null表示该操作返回空白页面<br/>
    </p>
    <pre class="brush:csharp;">
    using System;
    using System.Collections.Generic;
    using System.Text;
    using NFinal;

    namespace NFinalWeb3.Controllers
    {
        public class Index1Controller : BaseController
        {
            public ActionResult Index()
            {
                return null;
            }
        }
    }
    </pre>
    <h3>1.如何添加Json操作?</h3>
    <p>
        NFinal通过this.ViewBag.[变量名]=变量值的方式添加Json数据，<br/>
        最后通过return Json()返回所添加的Json数据。<br />
        该操作返回Json为：{"Code":1,"Message":"Hello World!"},<br />
        当你保存该文件时，VS会自动生成[控制器名].model.cs文件，<br />
        该文件中有Json结构对应的C#类，在执行return Json()时，<br />
        NFinal会自动使用该类进行Json序列化，以保证高效率序列化。<br />
    </p>
    <pre class="brush:csharp;">
    using System;
    using System.Collections.Generic;
    using System.Text;
    using NFinal;

    namespace NFinalWeb3.Controllers
    {
        public class Index1Controller : BaseController
        {
            public ActionResult Index()
            {
                this.ViewBag.Code=1;
                this.ViewBag.Message="Hello World!";
                return Json();
            }
        }
    }
    </pre>
    <h3>1.如何添加页面操作?</h3>
    <p>
        NFinal通过this.ViewBag.[变量名]=变量值的方式添加视图模板数据，<br/>
        最后通过this.View()调用View下的Razor模板返回html页面。<br />
        当你保存该文件时，VS会自动生成[控制器名].model.cs文件，<br />
        该文件就是视图模板数据对应的类文件。在建立模板时，<br />
        模板中就会有相应的字段提示，省去了记忆视图模板数据的麻烦。<br />
    </p>
    <pre class="brush:csharp;">
    using System;
    using System.Collections.Generic;
    using System.Text;
    using NFinal;

    namespace NFinalWeb3.Controllers
    {
        public class Index1Controller : BaseController
        {
            public ActionResult Index()
            {
                this.ViewBag.Title="Razor Test";
                this.ViewBag.Message="Hello World!";
                return View();
            }
        }
    }
    </pre>
</body>
</html>